package com.wlyuan.open.constants;

import lombok.Getter;

import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

/**
 * @author liing
 */
@Getter
public enum SmsType {
    REGISTER(1, "注册"),
    //auth
    LOGIN(2, "登录"),
    CHANGE_APP_SECRET(3, "重置appSecret短信"),
    BIND(4, "绑定管理员账号短信"),
    UNBIND_MOBILE(5, "换绑手机号短信"),
    //apollo
    REGISTER_APPROVED(6, "注册审核通过短信"),
    ;

    private Integer value;
    private String name;

    SmsType(Integer value, String name) {
        this.value = value;
        this.name = name;
    }

    private static final Map<Integer, SmsType> MAP = Arrays.asList(SmsType.values()).stream().collect(Collectors.toMap(SmsType::getValue, Function.identity()));

    public static SmsType fromValue(Integer value) {
        return Optional.ofNullable(value).map(MAP::get).orElse(null);
    }

    public static boolean isBind(Integer type) {
        return BIND.getValue().equals(type);
    }

    public static boolean isChangeAppSecret(Integer type) {
        return CHANGE_APP_SECRET.getValue().equals(type);
    }

    public static boolean isRegister(Integer type) {
        return REGISTER.getValue().equals(type);
    }
}
